#include "DropTreeView.h"

/**************************************************************************/
/**************************************************************************/
DropTreeView::DropTreeView(QWidget* parent) : QTreeView(parent)
{
    setAcceptDrops(true);
    setAutoFillBackground(true);

    QPalette palette;
    QColor myYellow(237,225,28,70);
    palette.setColor(QPalette::Highlight,myYellow);
    setPalette(palette);
}

/**************************************************************************/
/**************************************************************************/
void DropTreeView::dragEnterEvent(QDragEnterEvent *event)
{
     event->acceptProposedAction();
}

/**************************************************************************/
/**************************************************************************/
void DropTreeView::dragMoveEvent(QDragMoveEvent *event)
{
     event->acceptProposedAction();
}

/**************************************************************************/
/**************************************************************************/
void DropTreeView::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasUrls())
    {
        QList<QUrl> urlList = mimeData->urls();
        QString path = urlList.at(0).path();
        path.remove(0,1);
        emit fileReceived(path);
    }
    event->acceptProposedAction();
}

/**************************************************************************/
/**************************************************************************/
void DropTreeView::dragLeaveEvent(QDragLeaveEvent *event)
{
     event->accept();
}
